import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Vector;

public class Map_Stub extends JFrame {
	Map_Stub() {
		Map m = new Map();
		
		XMLHandler xml = new XMLHandler();
		Vector<CommandParameter> param = new Vector<CommandParameter>();
		
		param.add(new CommandParameter("n", 4));
		param.add(new CommandParameter("n0", 25));
		param.add(new CommandParameter("n1", 80));
		param.add(new CommandParameter("n2", 20));
		param.add(new CommandParameter("n3", 50));
		
		xml.addCommand(new ServerCommand("scan", param));
		xml.addCommand(new ServerCommand("move", new CommandParameter("real", 200)));
		xml.addCommand(new ServerCommand("rotate", new CommandParameter("real", 90)));
		xml.addCommand(new ServerCommand("move", new CommandParameter("real", 200)));
		xml.addCommand(new ServerCommand("scan", param));
		
		m.Update(xml);
//		m.Update("<r2s><rotate req=\"35 degrees\"/></r2s>");
//		m.Update("<r2s><move req=\"50 cm\"/></r2s>");
//		m.Update("<r2s><scan n=\"25\" n1=\"25\" n2=\"25\" n3=\"25\" n4=\"25\"/></r2s>");
//		m.Update("<r2s><rotate req=\"35 degrees\"/></r2s>");
//		m.Update("<r2s><move req=\"60 cm\"/></r2s>");
//		m.Update("<r2s><scan n=\"25\" n1=\"25\" n2=\"25\" n3=\"25\" n4=\"25\" n5=\"25\" /></r2s>");
//		m.Update("<r2s><rotate req=\"280 degrees\"/></r2s>");
//		m.Update("<r2s><move req=\"50 cm\"/></r2s>");
//		m.Update("<r2s><scan n=\"14\" n1=\"25\" n2=\"25\" n3=\"25\"/></r2s>");
//		m.Update("<r2s><rotate req=\"285 degrees\"/></r2s>");
//		m.Update("<r2s><move req=\"100 cm\"/></r2s>");
//		m.Update("<r2s><scan n=\"14\" n1=\"14\" n2=\"25\" n3=\"25\"/></r2s>");
//		m.Update("<r2s><rotate req=\"240 degrees\"/></r2s>");
//		m.Update("<r2s><move req=\"60 cm\"/></r2s>");
//		m.Update("<r2s><scan n=\"25\" n1=\"25\" n2=\"25\" n3=\"25\" n4=\"25\" n5=\"25\" /></r2s>");
		//m.repaint();
		add(m, BorderLayout.CENTER);
		setSize(m.map_size_height, m.map_size_width);
		getContentPane().addMouseListener(l);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	    try{
	    	BufferedImage bi = m.Yeild_Map();
		    File outputfile = new File("saved_map.png");
	    	ImageIO.write(bi, "png", outputfile);
	    } catch (IOException e) {
	        ;
	    }
	}
	
	MouseListener l = new MouseAdapter(){
		public void mouseClicked(MouseEvent e){
			System.out.println("["+e.getX()+", "+e.getY()+"]");
		}
	};
	
	public static void main(String[] args) {
		Map_Stub p = new Map_Stub();
	}

}
